﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CH04_07
{
    class clsStudent
    {
        // 成员字段;
        int iNum;                   // 学生学号;
        public string strName;      // 学生姓名;
        private int iAge;           // 学生年龄;
        private string strSex;      // 学生性别;
        public static int iCount;   // 静态字段,用于统计学生人数;

        // 声明公有、含参数的构造函数;
        public clsStudent(int num,string name,int age,string sex)
        {
            iNum = num;
            strName = name;
            iAge = age;
            strSex = sex;
            iCount++;
        }

        // 声明不含参数的构造函数;
        public clsStudent()
        {
            iNum = 201523;
            strName = "Willard";
            iAge = 19;
            strSex = "男";
            iCount++;
        }

        // 析构函数;
        ~clsStudent()
        {
            Console.WriteLine("学生类的析构函数被调用!");
        }

        // 学生入学;
        public void Enrollment()
        {
            Console.WriteLine("学号为:{0},姓名为:{1}同学入学!", iNum, strName);
        }

        // 学生长大1岁;
        public void Grow()
        {
            iAge++;
        }

        // 学生长大_iAgeSpan岁;
        public void Grow(int _iAgeSpan)
        {
            iAge += _iAgeSpan;
        }

        // 学生毕业;
        public void Graduate()
        {
            Console.WriteLine("学号为:{0},姓名为:{1}同学毕业!", iNum, strName);
        }

        // 输出信息;
        public void Display()
        {
            Console.WriteLine("学生学号为:{0}", iNum);
            Console.WriteLine("学生姓名为:{0}", strName);
            Console.WriteLine("学生年龄为:{0}", iAge);
            Console.WriteLine();
        }
    }
    class CH04_07
    {
        static void Main(string[] args)
        {
            // 调用含参数的构造函数初始化对象;
            clsStudent stu1 = new clsStudent(201623, "Chen", 18, "女");
            Console.WriteLine("现有学生人数为:" + clsStudent.iCount);

            clsStudent stu2 = new clsStudent();
            Console.WriteLine("现有学生人数为:" + clsStudent.iCount);

            clsStudent stu3 = new clsStudent();
            Console.WriteLine("现有学生人数为:" + clsStudent.iCount);
        }
    }
}
